Repository navigation
MLE-32970: Send Connection: close on gzipped rows requests - #1995
Open
prgs-rsingh wants to merge 4 commits into
Open
prgs-rsingh wants to merge 4 commits into
prgs-rsingh wants to merge 4 commits into
Conversation
…ndability StreamingOutputImpl previously hardcoded isRetryable()=false / isOneShot()=true for every wrapped OutputStreamSender, even when the originating write handle was fully buffered and resendable (e.g. JacksonHandle, StringHandle). This meant any request body built from such a handle -- including Row Manager plan execution, document writes, and Data Services parameters -- was needlessly blocked from being retried by RetryIOExceptionInterceptor after a transient connection error, even though the content could safely be written again. Thread each call site's already-known isResendable()/handleBase.isResendable() value into StreamingOutputImpl instead of assuming non-resendable: - writeDocumentImpl-style document writes - putPostValueImpl - postResource / putResource (used by RowManagerImpl for Optic plan execution) - postIteratedResourceImpl (multipart-mixed eval/invoke style resources) - addParts multipart builder - makeRequestBodyForContent and BaseProxy's makeRequestBody (Data Services single-node parameters) Call sites without an existing resendable concept (structured query search, alert match) keep the prior conservative false/one-shot default via new 3-arg doPost/doPut overloads, so behavior is unchanged where resendability was never determined. Added StreamingOutputImplTest cases covering: a resendable body being retried after a simulated connection failure, and a non-resendable part inside a MultipartBody still propagating isOneShot()=true so it is never retried. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The change ignores legacy retry opt-outs and uploads one-shot bodies after unsuccessful preflight retries, risking resends of consumed content and ResourceNotResendableException failures.
2 open issues
What changed in this PR
This PR addresses connection reuse and one-shot request handling in the core Java client, aiming to prevent failed uploads after MarkLogic closes a gzip-enabled rows connection.
Changes:
- Adds a network interceptor that requests connection closure for gzip responses with trailers.
- Uses OkHttp’s
isOneShot()contract for retry decisions and centralizes digest-authentication preflight pings. - Closes buffered multipart responses promptly and adds streaming-request regression tests.
| File | Description |
|---|---|
marklogic-client-api/src/test/java/com/marklogic/client/impl/StreamingPartRequestTest.java |
Adds connection reuse, streaming failure, and digest-authentication tests. |
marklogic-client-api/src/test/java/com/marklogic/client/impl/StreamingOutputImplTest.java |
Tests handle resendability and multipart retry behavior. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/StreamingOutputImpl.java |
Reports one-shot status from handle resendability. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java |
Centralizes body construction and preflight pings; closes buffered responses. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/RetryIOExceptionInterceptor.java |
Uses one-shot status to bypass retries. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/RetryableRequestBody.java |
Deprecates the legacy retry contract. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/ChunkedGzipConnectionCloseInterceptor.java |
Adds the gzip/trailers connection-close workaround. |
Review effort: Balanced
prgs-rsingh
force-pushed
the
MLE-32953-connection-close
branch
from
November 24, 2026 04:41
a41b4a6 to
d100c10
Compare
prgs-rsingh
force-pushed
the
MLE-32953-connection-close
branch
from
November 24, 2026 04:48
d100c10 to
10c78a5
Compare
hmadala001
force-pushed
the
MLE-32953-connection-close
branch
from
December 1, 2026 06:22
0eaf4a4 to
8e52d57
Compare
MarkLogic answers a request that has both "TE: trailers" and "Accept-Encoding: gzip" (every /v1/rows call) with a chunked, gzipped response marked "Connection: Keep-Alive", and then closes the connection. OkHttp reuses that dead connection, so a following request with a one-shot body (e.g. a Reader) fails and cannot be resent. A Data Services call with a streaming parameter, made right after RowManager.resultRows(), failed this way with "Stream closed". - ChunkedGzipConnectionCloseInterceptor adds "Connection: close" to such requests on HTTP/1.1, so OkHttp does not pool the connection. This is a workaround until the server bug is fixed. - Every request body is built by toRequestBody, so isOneShot() always reflects the handle's isResendable(), also inside a MultipartBody. OkHttp and RetryIOExceptionInterceptor then never resend a consumed body. RetryableRequestBody is deprecated; RetryIOExceptionInterceptor still honors it for bodies that do not override isOneShot(). - With digest authentication, a body-less ping takes the 401 challenge before the first one-shot request on a thread. This is now done in sendRequestOnce, so it covers every call path. If the server is still unavailable after the ping retries, the request fails with a FailedRetryException instead of sending a body that would be lost. StreamingPartRequestTest and ChunkedGzipConnectionCloseInterceptorTest use a mock server. StreamingOutputImplTest checks isOneShot() for each handle type. MLE-32953 MLE-32953 Test the connection pool keep-alive without MarkLogic - OkHttpUtilConnectionPoolTest verifies against a mock server that the shared pool drops a connection before it has been idle for 5 seconds, still reuses one that has just become idle, and can be replaced by an OkHttpClientConfigurator. - The comment on the pool states that the 4 seconds assume the default keep-alive timeout of an app server and how to replace the pool. - StreamingRequestOnReusedConnectionTest removes the retry interceptor that Common adds, so that its clients match an application's client. Update LockForUpdateTest.java
hmadala001
force-pushed
the
MLE-32953-connection-close
branch
from
December 1, 2026 06:22
8e52d57 to
b25f2f2
Compare
…mits - The ping that precedes the first one-shot request with digest authentication is retried within the configured retry limits (at least 8 retries and up to 120 seconds by default) with the usual backoff, instead of 10 times about 150 ms apart. A streamed document write already waited that long before this branch. - StreamingPartRequestTest covers the limits, and a server that becomes available after a few pings. - LockForUpdateTest: the copyright year and the assertion message match the change that was made to the test.
prgs-rsingh
marked this pull request as ready for review
December 1, 2026 11:00
prgs-rsingh
requested review from
NiteshMehta,
adganta,
ashokrprogress,
hmadala001,
rjrudin and
vishwach
as code owners
December 1, 2026 11:00
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Shared connection-pool and digest preflight changes affect every client and require deployed-server validation of MarkLogic connection-closing and load-balancer interactions, which was unavailable during review.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
NiteshMehta
approved these changes
Dec 1, 2026
hmadala001
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
The released client (8.2.0) can store an empty document without reporting an error. A write with a body that can only be read once, such as an
InputStreamHandle, can be sent on a connection that MarkLogic has already closed. The attempt fails after the body has been consumed, OkHttp silently sends the request again on a new connection with nothing left to send, and MarkLogic stores the empty body. In the same situation, a Data Services call with a streaming parameter (for example aReader) fails intermittently.There are three causes:
TE: trailersandAccept-Encoding: gzipwith a chunked, gzipped response markedConnection: Keep-Alive, and then closes the connection. Every/v1/rowscall from this client sends both headers, so OkHttp puts a dead connection back in its pool.Changes
ChunkedGzipConnectionCloseInterceptoraddsConnection: closeto HTTP/1.1 requests that have both headers, so OkHttp does not pool the connection. The server closes that connection anyway, so no connection reuse is lost. It is a network interceptor so that it sees the headers that are actually sent, including when gzip is disabled withRemoveAcceptEncodingConfigurator. This is a client workaround until the server is fixed.toRequestBody, soisOneShot()always reflects the handle'sisResendable(), also inside aMultipartBody. OkHttp andRetryIOExceptionInterceptorthen never resend a consumed body, and the real failure is reported instead of an empty document being written orStream closedbeing thrown.RetryableRequestBodyis deprecated;RetryIOExceptionInterceptorstill honors it for bodies that do not overrideisOneShot().sendRequestOnce, so it covers every call path. If the server is unavailable, the ping is retried within the same limits as any other retried request (com.marklogic.client.minimumRetriesandcom.marklogic.client.maximumRetrySeconds; 8 retries and 120 seconds by default). If it is still unavailable after that, the request fails with aFailedRetryExceptioninstead of sending a body that would be lost.OkHttpUtil) now drops a connection after it has been idle for 4 seconds, instead of OkHttp's default of 5 minutes. MarkLogic closes the connection after 5 seconds anyway, so no connection reuse is lost when connecting to MarkLogic directly.Behavior changes
OkHttpClientConfiguratorthat callsOkHttpClient.Builder#connectionPooltoDatabaseClientFactory.addConfigurator. Configurators are applied after the default pool is set.Tests
StreamingRequestOnReusedConnectionTest(MarkLogic): a document written from anInputStreamHandlearrives in full right after a gzipped rows request, and after the connection has been idle for 7 seconds with gzip disabled. Its clients do not have the retry interceptor that the other tests get fromCommon.OkHttpUtilConnectionPoolTest(mock server): the shared pool drops a connection before it has been idle for 5 seconds, still reuses a connection that has just become idle, and can be replaced by a configurator.StreamingPartRequestTest(mock server): a streaming request after a rows request succeeds; the connection is kept when gzip is disabled; a failed streaming request is not resent; digest authentication pings only before the first streaming request; a streaming request is not sent when the pings find the server unavailable for the configured retry period, and is sent once after the server becomes available.ChunkedGzipConnectionCloseInterceptorTest(mock server): an HTTP/1.1 connection is not reused, an HTTP/2 connection is.StreamingOutputImplTest:isOneShot()for each handle type and for multipart bodies; a body that only implements the deprecatedRetryableRequestBodyis still not retried.Notes
LockForUpdateTesthas a timing fix that is unrelated to this change: the plan could run before the eval had taken the lock.xdmp:set-response-chunked-encoding(true)cannot be detected from the request headers.